<?php
namespace app\controller;

use app\BaseController;
use app\controller\model\Tables;
use liliuwei\think\Auth;
use think\facade\Session;
use think\facade\Db;
class OtherUser extends BaseController
{
    protected $getpath="";
	protected $tables;
    protected $gobaluser="";
    public function __construct(){
        checkuser();
        $this->gobaluser=Session::get("uid");
		$this->tables = new Tables();
    }
    public function supplier(){
	    return view("otherUser/supplier");
    }
    public function supplierR(){
	    $where='1=1';
	    $status = request()->param("status");
	    $status==-1?$where.=" and status=-1":$where.=' and status=1';
	    $title = request()->param("title");
	    $title!=''?$where.=" and title like '%$title%'":'';
	    getpagedata($this->tables->supplier,"",false,$where);
    }
	public function supplierW(){
		if(request()->isGet()){
			$id = request()->get('id');
			if($id>0){
				$re = DB::name($this->tables->supplier)->where("id",$id)->find();
				if(!$re) echojson([],1,'ID错误');
				return view("otherUser/supplierW")->assign(['data'=>$re]);
			}
			return view("otherUser/supplierW");
		}else{
			$data = request()->post();
			$id = request()->get('id');
			$del = request()->get('del');
			if($id>0){
				$re = DB::name($this->tables->supplier)->where("id",$id)->find();
				if(!$re) echojson([],1,'ID错误');
				if($del=='true'){
					$up  = DB::name($this->tables->supplier)->where("id",$id)->update(['status'=>-1]);
					if(!$up) echojson([],1,'删除失败');
				}else{
					$up  = DB::name($this->tables->supplier)->where("id",$id)->update($data);
					if(!$up) echojson([],1,'更新失败');
				}

			}else{
				$data['addTime']=nowTime();
				$up  = DB::name($this->tables->supplier)->insert($data);
				if(!$up) echojson([],1,'添加失败');
			}
			echojson();
		}
	}
    public function auction(){
	    return view("otherUser/auction");
    }
    public function auctionR(){
	    $where='1=1';
	    $status = request()->param("status");
	    $status==-1?$where.=" and status=-1":$where.=' and status=1';
	    $title = request()->param("title");
	    $title!=''?$where.=" and title like '%$title%'":'';
	    getpagedata($this->tables->auction,"",false,$where);
    }
	public function auctionW(){
		if(request()->isGet()){
			$id = request()->get('id');
			if($id>0){
				$re = DB::name($this->tables->auction)->where("id",$id)->find();
				if(!$re) echojson([],1,'ID错误');
				return view("otherUser/auctionW")->assign(['data'=>$re]);
			}
			return view("otherUser/auctionW");
		}else{
			$data = request()->post();
			$id = request()->get('id');
			$del = request()->get('del');
			if($id>0){
				$re = DB::name($this->tables->auction)->where("id",$id)->find();
				if(!$re) echojson([],1,'ID错误');
				if($del=='true'){
					$up  = DB::name($this->tables->auction)->where("id",$id)->update(['status'=>-1]);
					if(!$up) echojson([],1,'删除失败');
				}else{
					$up  = DB::name($this->tables->auction)->where("id",$id)->update($data);
					if(!$up) echojson([],1,'更新失败');
				}
			}else{
				$data['addTime']=nowTime();
				$up  = DB::name($this->tables->auction)->insert($data);
				if(!$up) echojson([],1,'添加失败');
			}
			echojson();
		}
	}
	public function getOtherUserOption(){

	}
}
